let val = [];
let listLength = 0;
Component({
  properties: {
    list: {
      type: Array,
      value: []
    }
  },
  data: {
    value: [],
    btnEnable: true, // 确认按钮是否可以点击
    listOriginal: [], // list原始数据
  },
  methods: {
    // 设置数据
    setPickViewData(list) {
      if (list.length) {
        val = []
        let value = JSON.parse(JSON.stringify(val))
        for (let i = 0; i < list.length; i++) {
          value.push(0)
        }
        this.setData({
          value
        })
      }
      this.setData({
        list
      })
      this.setData({
        listOriginal: JSON.parse(JSON.stringify(this.data.list))
      })
    },
    // 取消
    onCancle() {
      this.selectComponent('#pickerPopup').onHidePopup()
      this.triggerEvent('onPickerCancle')
    },
    // 确定
    onConfig() {
      if (!this.data.btnEnable) return
      let name = '';

      let index = this.data.value
      for (let i = 0; i < index.length; i++) {
        if (this.data.list[i]) {
          if (i > 0) {
            name += ' '
          }
          name += this.data.list[i][index[i]].name
        }
      }

      this.selectComponent('#pickerPopup').onHidePopup()
      this.triggerEvent('onPickerConfig', {
        index,
        name
      })
    },
    // 滚动中
    bindChange(e) {
      val = e.detail.value
    },
    // 滚动开始
    bindPickstart(e) {
      this.setData({
        btnEnable: false,
      })
    },
    // 滚动结束
    bindPickend(e) {
      this.setData({
        value: val,
        list: this.data.list,
        btnEnable: true
      })
    },
    // 打开弹窗
    onShowPopup() {
      this.selectComponent('#pickerPopup').onShowPopup()
    },


  }
});